package com.aisino.controller;

import com.aisino.entity.TreeNode;
import com.aisino.entity.TreeNode2;
import com.aisino.utils.TreeUtil;
import com.aisino.utils.TreeUtilBySjzl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/dataSecurity")
public class DataSecurityController {
    @GetMapping("/listTree")
    public List<TreeNode> listTree(){
        //模拟数据
        List<TreeNode> treeNodeList = new ArrayList<>();
        treeNodeList.add(new TreeNode(1,"顶级节点A",0));
        treeNodeList.add(new TreeNode(2,"顶级节点B",0));
        treeNodeList.add(new TreeNode(3,"二级节点A1",1));
        treeNodeList.add(new TreeNode(4,"二级结点B1",2));
        treeNodeList.add(new TreeNode(5,"二级节点B2",2));
        treeNodeList.add(new TreeNode(6,"三级节点A1-1",3));
        treeNodeList.add(new TreeNode(7,"三级节点A1-2",3));
        treeNodeList.add(new TreeNode(8,"四级节点A1-1-1",6));
        treeNodeList.add(new TreeNode(9,"四级节点A1-1-2",6));
        treeNodeList.add(new TreeNode(10,"五级节点A1-1-1-1",8));
        long start = System.currentTimeMillis();
        List<TreeNode> treeNodes = TreeUtil.buildTree(treeNodeList);
        System.out.println("耗时："+(System.currentTimeMillis() - start));
        return treeNodes;
    }

    @GetMapping("/listTreeBySjzl")
    public List<TreeNode2> listTreeBySjzl(){
        //模拟数据
        List<TreeNode2> treeNodeList = new ArrayList<>();
        treeNodeList.add(new TreeNode2(1,"顶级节点A",0));
        treeNodeList.add(new TreeNode2(2,"顶级节点B",0));
        treeNodeList.add(new TreeNode2(3,"二级节点A1",1));
        treeNodeList.add(new TreeNode2(4,"二级结点B1",2));
        treeNodeList.add(new TreeNode2(5,"二级节点B2",2));
        treeNodeList.add(new TreeNode2(6,"三级节点A1-1",3));
        treeNodeList.add(new TreeNode2(7,"三级节点A1-2",3));
        treeNodeList.add(new TreeNode2(8,"四级节点A1-1-1",6));
        treeNodeList.add(new TreeNode2(9,"四级节点A1-1-2",6));
        treeNodeList.add(new TreeNode2(10,"五级节点A1-1-1-1",8));
        long start = System.currentTimeMillis();
        List<TreeNode2> treeNodes = TreeUtilBySjzl.buildTreeBy2Loop(treeNodeList,0);
        System.out.println("耗时："+(System.currentTimeMillis() - start));
        return treeNodes;
    }
}
